import 'package:todo_app/constants/Screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

import 'OverlaySupport.dart';


class OverlayLoading extends StatelessWidget {
  final String? title;
  const OverlayLoading({ Key? key, this.title }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final Widget pageChild = SpinKitFadingCircle(color: Colors.black);
    return Container(
      alignment: Alignment.center,
      color: Colors.transparent,
      child: Container(
        width: Screen.sizeByDesign(128),
        height: Screen.sizeByDesign(128),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(Screen.sizeByDesign(16)),
          boxShadow: [
            BoxShadow(
              blurRadius: 4,
              color: Color(0x08000000),
              offset: Offset(0, 2),
            )
          ]
        ),
        padding: EdgeInsets.symmetric(horizontal: Screen.sizeByDesign(10)),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            pageChild,
            SizedBox(height: Screen.sizeByDesign(6)),
            title == null || title!.isEmpty ? null : Text(title!, style: TextStyle(color: Colors.black, fontSize: Screen.sizeByDesign(14)),)
          ].where((item)=> item != null).map((e) => e as Widget).toList()
        ),
      )
    );
  }
}

OverlayEntry showOverlayLoading({
  String? title
}) {
  return showOverlay(
    builder: (BuildContext _, OverlaySupportState state) {
      return OverlayLoading(title: title);
    }
  );
}
